package leetcode;

import java.util.ArrayList;
import java.util.List;

public class ListNode {
    public static void main(String[] args) {
        String s ="123123";

    }
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }

    public static ListNode createListNode(int[] arr){
        if(arr.length==0){
            return null;
        }
        ListNode head = new ListNode(arr[0]);
        ListNode befor=head;
        for (int a=1;a<arr.length;a++){
            ListNode node = new ListNode(arr[a]);
            head.next=node;
            head=node;
        }
        return befor;
    }

    public static List<Integer> createArr(ListNode head){
        ArrayList<Integer> arrayList= new ArrayList<>();
        while(head!=null){
            arrayList.add(head.val);
            head=head.next;
        }
        return arrayList;
    }

    public static void showListNode(ListNode head){
        while(head!=null){
            System.out.println(head.val+" ");
            head=head.next;
        }
    }

    public static int[] createArray(int length){
        int[] a = new int[length+1];
        for (int b=0;b<=length;b++){
            a[b]=b;
        }
        return a;
    }
}
